<?php
class FundsAction extends Action {
	public function index() {
		$this->assign ( 'title', '羽毛球积分赛 - 经费管理' );
		
		// 判断用户登录信息
		$this->assign ( 'admin', 'none' );
		$this->assign ( 'newrecord', 'none' );
		if (session ( 'username' )) {
			$this->assign ( 'loginuser', session ( 'username' ) );
			$this->assign ( 'userscore', session ( 'userscore' ) );
			$this->assign ( 'usermatchcount', session ( 'usermatchcount' ) );
			$this->assign ( 'loginusercolor', get_color ( session ( 'usergender' ) ) );
			
			if (intval ( session ( 'userlevel' ) ) < 1) {
				$this->assign ( 'userstatus', '（未认证）' );
			} else {
				$this->assign ( 'userstatus', '' );
				$this->assign ( 'newrecord', 'inline' );
			}
			
			if (intval ( session ( 'userlevel' ) ) > 1) {
				$this->assign ( 'admin', 'inline' );
			}
			
			$this->assign ( 'logoffblock', 'inline' );
			$this->assign ( 'loginblock', 'none' );
		} else {
			$this->assign ( 'logoffblock', 'none' );
			$this->assign ( 'loginblock', 'inline' );
		}
		
		$users = M ( 'Users' );
		$data = $users->where ( 'total_in>0' )->order ( 'balance desc' )->field ( 'user_id,username,gender,balance,total_in,total_out,recent_act_date,change_count' )->select ();
		for($i = 0; $i < count ( $data ); $i ++) {
			$user_gender [$data [$i] ['username']] = $data [$i] ['gender'];
			$data [$i] ['color1'] = get_color ( $data [$i] ['gender'] );
			$name [$data [$i] ['user_id']] = $data [$i] ['username'];
		}
		$this->assign ( 'accountlist', $data );
		
		$records = M ( 'ActRecords' );
		$data = $records->order ( 'date desc,id desc' )->select ();
		for($i = 0; $i < count ( $data ); $i ++) {
			$ids = split ( ",", $data [$i] ['participants'] );
			$names = "";
			foreach ( $ids as $id ) {
				//$name [$id] = "<font color=\"" . get_color($user_gender[$name [$id]]) . "\">" . $name [$id] . "</font>";
				$names = $names . $name [$id] . ", ";
			}
			$names = substr ( $names, 0, - 2 );
			$data [$i] ['participants'] = $names;
			if ($data [$i] ['is_act'] == 1) {
				$data [$i] ['color'] = '#FFFFFF';
			} else {
				$data [$i] ['color'] = '#F0F0F0';
			}
		}
		$this->assign ( 'actionlist', $data );
		
		$this->display ();
	}
}